<?
include('adodb/adodb-exceptions.inc.php'); 
require ("comun/ini.php");
if(isset($_POST['JsonEnv'])){
	$JsonRec = new Services_JSON();
	$JsonEnv = new Services_JSON();
	$JsonRec=$JsonRec->decode(str_replace("\\","",$_POST['JsonEnv']));
	try {
		$q = "SELECT A.*, COALESCE(current_date - (SELECT MAX(fecha) FROM experticias WHERE id_vehiculo = A.id AND estatus <>'A'),-1) AS dias_ultima_experticia FROM vehiculos AS A WHERE A.carroceria='$JsonRec->Carroceria' LIMIT 1";
		$r = $conn->Execute($q);
		$i=0;
		//die($q);
		while(!$r->EOF){
			$Vehiculo[$i]['P'] = $r->fields['placa'];
			$Vehiculo[$i]['M'] = $r->fields['id_marca'];
			$Vehiculo[$i]['O'] = $r->fields['id_modelo'];
			$Vehiculo[$i]['I'] = $r->fields['id_tipo'];
			$Vehiculo[$i]['C'] = $r->fields['id_color'];
			$Vehiculo[$i]['A'] = $r->fields['anio'];
			$Vehiculo[$i]['U'] = $r->fields['id_uso'];
			$Vehiculo[$i]['R'] = $r->fields['carroceria'];
			$Vehiculo[$i]['T'] = $r->fields['motor'];
			$Vehiculo[$i]['D'] = $r->fields['dias_ultima_experticia'];
			$Vehiculo[$i]['SM'] = $r->fields['motor'];
			$Vehiculo[$i]['SC'] = $r->fields['serial_carrozado'];
			$Vehiculo[$i]['CL'] = $r->fields['clase'];
			$Vehiculo[$i]['PU'] = $r->fields['puestos'];
			$Vehiculo[$i]['EJ'] = $r->fields['ejes'];
			$Vehiculo[$i]['TA'] = $r->fields['tara'];
			$Vehiculo[$i]['CC'] = $r->fields['capacidad_carga'];
			$Vehiculo[$i]['SE'] = $r->fields['servicio'];
			$Vehiculo[$i]['RE'] = $r->fields['registro'];
			$Vehiculo[$i]['CH'] = $r->fields['chasis'];
			
			$i++;
			$r->movenext();
		}
		if(is_array($Vehiculo)){
			echo $JsonEnv->encode($Vehiculo);
		}else{
			echo false;
		}
	}catch( ADODB_Exception $e ){
		//	echo ERROR_CATCH_GENERICO;
		echo false;
	}
} 
?>